package com.learn.spring.mybatis.core;

import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;
import java.lang.reflect.Proxy;

public class MyFactoryBean implements FactoryBean {
    private Class myInterface;

    public MyFactoryBean(Class myInterface) {
        this.myInterface = myInterface;
    }

    @Override
    public Object getObject() throws Exception {
        return Proxy.newProxyInstance(this.getClass().getClassLoader(),
                new Class[]{myInterface},
                (proxy, method, args) -> {
                    System.out.println(method.getAnnotation(Select.class).value()[0]);
                    return null;
                });
    }

    @Override
    public Class<?> getObjectType() {
        return myInterface;
    }
}
